/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#pragma once


#include <kmhdfs/common/hash.h>
#include <kmhdfs/client/user_info.h>

#include <string>

namespace Hdfs {
    namespace Internal {
        class FileSystemKey {
        public:
            FileSystemKey(const std::string &uri, const char *user);

            FileSystemKey(const std::string &auth, const std::string &host,
                          const std::string &port, const std::string &scheme,
                          const std::string &user, size_t u) : authority(auth), host(host), port(port), scheme(scheme),
                                                               user(user) {
            }

            bool operator ==(const FileSystemKey &other) const {
                return scheme == other.scheme && authority == other.authority;
            }

            size_t hash_value() const {
                size_t values[] = {StringHasher(scheme), StringHasher(authority)};
                return CombineHasher(values, sizeof(values) / sizeof(values[0]));
            }

            const std::string &getHost() const {
                return host;
            }

            void setHost(const std::string &host) {
                this->host = host;
            }

            const std::string &getPort() const {
                return port;
            }

            void setPort(const std::string &port) {
                this->port = port;
            }

            const std::string &getScheme() const {
                return scheme;
            }

            void setScheme(const std::string &scheme) {
                this->scheme = scheme;
            }

            const UserInfo &getUser() const {
                return user;
            }

            void setUser(const UserInfo &user) {
                this->user = user;
            }

            void addToken(const Token &token) {
                user.addToken(token);
            }

        private:
            std::string authority;
            std::string host;
            std::string port;
            std::string scheme;
            UserInfo user;
        };
    }
}

HDFS_HASH_DEFINE(Hdfs::Internal::FileSystemKey);
